home *** CD-ROM | disk | FTP | other *** search
- /*
- ********************
- * PeterSoft's Bob *
- ******************** < body.cpp >
-
- This program is written by Peter Hsieh and Jeffery Hu, and
- is finished on July 21, 1995.
-
- The purpose of this program is to demostrate the basic sprite
- skills that are applied on the computer graphic animations.
-
- Body.exe is for mod-13 (MCGA) and Bodyh.exe is for 640*480*
- 256 colors resolution. Just simply choose the proper include
- file and video initialization function.
-
- If you are interest to contact us, please write to
-
- 24 Cecil Street
- Toronto, Ontario
- M5T 1N2 Canada
-
- Email: g3jjhh@cdf.utoronto.ca
- zhsieh@undergrad.math.uwaterloo.ca
- */
-
- # include "a:\work\mod13.h" // header file for MCGA
- //# include "a:\work\vgahi.h" // header file for 640*480*256 colors
- # include "a:\work\graph.h"
- # include "a:\person\data.h"
-
- void drawbody (int, int, int, int); // draw dog body
- void drawhand (int, int, int, int); // hand
- void drawleg (int, int, int, int); // leg
- void changesprite (); // change the components of dog
- void dog (); // draw the whole dog
- void recover (); // erase the previous image
-
- void main ()
- {
- char c[1];
-
- mode13 (); // to access mode 13
- // vesa (); // to access vesa 640*480*256 colors mode
- printf ("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n PeterSoft's BOB");
- drawbody (0, 0, 0, 0); // sample to show all components
- drawhand (0, 0, 26, 0);
- drawleg (0, 0, 40, 0);
- drawleg (1, 0, 55, 0);
- drawleg (2, 0, 70, 0);
- drawleg (3, 0, 85, 0);
- dog ();
- do {
- c[0]= getch ();
- switch (c[0])
- {
- case 75: //left
- if (spritx> LEFT)
- {
- recover ();
- spritx-= BODYINC;
- dog ();
- }
- break;
- case 77: // right;
- if (spritx< RIGHT)
- {
- recover ();
- spritx+= BODYINC;
- dog ();
- }
- break;
- default:
- break;
- }
- } while (c[0]!= 'q');
-
- textmode (); // back to text mode
- }
-
- void drawbody (int n, int x, int y, int dis)
- {
- int i, j;
-
- for (i= 0; i< ICONH; i++)
- for (j= 0; j< ICONW; j++)
- if (body[n][i][j]!= -1)
- pixel (x+ j, y+ i, body[n][i][j]+ dis);
- }
-
- void drawhand (int n, int x, int y, int dis)
- {
- int i, j;
-
- for (i= 0; i< HANDW; i++)
- for (j= 0; j< HANDH; j++)
- if (hand[n][j][i]!= -1)
- pixel (x+ i, y+ j+ 4, hand[n][j][i]+ dis);
- }
-
- void drawleg (int n, int x, int y, int dis)
- {
- int i, j;
-
- for (i= 0; i< LEGW; i++)
- for (j= 0; j< LEGH; j++)
- if (leg[n][i][j]!= -1)
- pixel (x+ j, y+ i, leg[n][i][j]+ dis);
- }
-
- void dog ()
- {
- changesprite ();
- drawleg (leg2, spritx+ 11, sprity+ 18, 14);
- drawhand (0, spritx+ 10- handx1, sprity+ 11, -2);
- drawbody (0, spritx, sprity, 0);
- drawhand (0, spritx+ 10- handx2, sprity+ 10, 0);
- drawleg (leg1, spritx+ 9, sprity+ 18, 0);
- }
- void changesprite ()
- {
- if (handx1== 0 || handx1== 7)
- handinc= -handinc;
- handx1-= handinc;
- handx2+= handinc;
- if (leg1==0 || leg1 == 3)
- leginc=-leginc;
- leg1-= leginc;
- leg2+= leginc;
- }
-
- void recover ()
- {
- bar (spritx, sprity, spritx+ ICONW, sprity+ 35, 0, 0);
- }